package com.qianfeng1.day7_连接池.chan;


import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * 作者：黎杭
 * 日期：2020/2/18
 * <p>
 * 错误代码示例
 */
public class TestMoreThreadChange {
    public static void main(String[] args) throws ParseException, ExecutionException, InterruptedException {

        ExecutorService executorService = Executors.newCachedThreadPool();// 创建一个缓冲的线程池
        List<Future<Date>> list = new ArrayList<>();
        for (int x = 0; x < 10; x++) {
            Future<Date> submit = executorService.submit(new Callable<Date>() {
                @Override
                public Date call() throws Exception {
                    LocalDate localDate = LocalDate.parse("2019-02-18");// 一年前日期
                    Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();// 获取时间戳对象
                    return Date.from(instant);
                }
            });// 此时会得到FutureTask对象
            list.add(submit);
        }
        for (Future<Date> f : list) {
            Date date = f.get();// 获取线程最后返回的日期
            System.err.println(date);
        }

    }
}
